﻿using System;
using System.Windows.Forms;
using Dapper;
using ExtendLib.Helper;

namespace SmsBomb
{
    public partial class LogMgr : Form
    {
        public LogMgr()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 窗口加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LogMgr_Load(object sender, EventArgs e)
        {
            InitBind();
        }
        /// <summary>
        /// 清空日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string cmd = "Delete from LogInfo where Id>0";
            using (var conn = DbHelperByDapper.OpenConnection())
            {
                int r = conn.Execute(cmd);
                if (r > 0)
                {
                    MessageBox.Show("清空完毕！");
                    InitBind();
                }
            }
        }
        /// <summary>
        /// 默认数据绑定
        /// </summary>
        private void InitBind()
        {
            //获取一小时内的1000条
            string where = string.Format("where CreateTime>'{0}'", DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd"));

            var list = DbHelperByDapper.GetListPages<LogModel>(1, 1000, where);
            dgvLogList.DataSource = list;
        }
        /// <summary>
        /// 配置信息查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnControl_Click(object sender, EventArgs e)
        {
            var list = ControlHelper.GetListByType(EOtherType.空);
            dgvLogList.DataSource = list;
        }
    }
}
